/*
 *    Copyright 2009-2019 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.lm.base;

import org.apache.ibatis.builder.StaticSqlSource;
import org.apache.ibatis.builder.xml.XMLConfigBuilder;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ParameterMapping;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.session.Configuration;
import org.junit.Test;
import org.lm.base.pojo.Student;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

/**
 * @Auther: Min.Liu
 * @Description:
 * @Date: Created in 19:34 2025/3/27
 */
public class Demo2 {

  @Test
  public void testMappedStateMent() throws IOException {
    String resource = "org/lm/base/mybatis-config.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder(inputStream);
    Configuration configuration = xmlConfigBuilder.parse();
    ParameterMapping mapping1 = new ParameterMapping.Builder(configuration, "sname", String.class).build();
    StaticSqlSource sqlSource = new StaticSqlSource(configuration, " insert into student value(null,#{sname},#{cid})", Arrays.asList(mapping1));
    MappedStatement statement = new MappedStatement.Builder(configuration,"insert2",sqlSource, SqlCommandType.INSERT).build();
    BoundSql boundSql = statement.getBoundSql(new Student());
    System.out.println(boundSql.getSql());
  }
}
